//============================================================================
// Name        : cpp_localip.cpp
// Author      : darkflash
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <arpa/inet.h>
#include <netdb.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <iostream>

#define MAXHOSTNAMELEN 255
using namespace std;

int main() {
	char* hostname = (char*)malloc(MAXHOSTNAMELEN);
	memset(hostname, 0, MAXHOSTNAMELEN);
	gethostname(hostname, MAXHOSTNAMELEN);
	cout << "host: " << hostname<< endl;

	struct hostent* he;
	struct in_addr a;

	he = gethostbyname(hostname);
	if(he){
		while(*he->h_addr_list){
			bcopy(*he->h_addr_list++, (char*)&a, sizeof(a));
			cout << inet_ntoa(a) << endl;
		}
	}

	return 0;
}
